package demo7;

import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

@Component
public class Person implements InitializingBean, DisposableBean {
    private String name;
    private int age;
    private String sex;
    public Person(){
        System.out.println("1:Person()的构造器执行了");
    }
    @Override
    public void afterPropertiesSet() throws Exception {
        System.out.println("3:Person对象被容器完整初始化完毕");
    }
    @Override
    public void destroy() throws Exception {
        System.out.println("容器即将销毁，通知Person,调用destroy()方法");

    }
    @Value("张三")
    public void setName(String name)
    {
        System.out.println("2:初始化name属性，setName()方法执行了");
        this.name = name;
    }
    @Value("18")
    public void setAge(int age){
        System.out.println("2:初始化age属性，setAge()方法执行了");
    }
    @Value("男")
    public void setSex(String sex){
        System.out.println("2:初始化sex属性，setSex()方法执行了");
    }

    public void play(){
        System.out.println("4:Person 中的正常方法play()执行了");
    }



}
